package com.zx.article.editor.service.impl;

import java.util.List;

import com.zx.article.editor.dao.IEditorDao;
import com.zx.article.editor.dao.impl.EditorDaoImpl;
import com.zx.article.editor.model.EditorModel;
import com.zx.article.editor.service.IEditorService;
import com.zx.article.util.FmtRequest;

public class EditorServiceImpl implements IEditorService {

	private IEditorDao editorDao = new EditorDaoImpl();

	@Override
	public List<EditorModel> get(EditorModel editorModel) {
		editorModel.setAccount(editorModel.getAccount() == null ? null : "%" + editorModel.getAccount() + "%");
		editorModel.setNickName(editorModel.getNickName() == null ? null : "%" + editorModel.getNickName() + "%");
		editorModel.setRealName(editorModel.getRealName() == null ? null : "%" + editorModel.getRealName() + "%");
		return editorDao.queryList(editorModel);
	}

	@Override
	public List<EditorModel> getAll() {
		return editorDao.queryList(new EditorModel());
	}

	@Override
	public EditorModel getModel(String account) {
		return editorDao.querModel(account);
	}

	@Override
	public String del(String account) {
		return "1".equals(editorDao.deleteModel(account)) ? "success" : "fail";
	}

	@Override
	public String add(EditorModel editorModel) {
		return "1".equals(editorDao.insertModel(editorModel)) ? "success" : "fail";
	}

	@Override
	public String updata(EditorModel editorModel) {
		return "1".equals(editorDao.updataModel(editorModel)) ? "success" : "fail";
	}

	@Override
	public String reset(EditorModel editorModel) {
		editorModel.setPassword(new FmtRequest().encode("123"));
		return "1".equals(editorDao.updataModel(editorModel)) ? "success" : "fail";
	}

	@Override
	public int getCount(EditorModel editorModel) {
		editorModel.setAccount(editorModel.getAccount() == null ? null : "%" + editorModel.getAccount() + "%");
		editorModel.setNickName(editorModel.getNickName() == null ? null : "%" + editorModel.getNickName() + "%");
		editorModel.setRealName(editorModel.getRealName() == null ? null : "%" + editorModel.getRealName() + "%");
		return editorDao.queryCount(editorModel);
	}

}
